# 添加子目录
add_subdirectory(main)
add_subdirectory(other_module)

# 引入全局变量的属性
# src的源文件
get_property(${PROJECT_NAME}_SOURCE GLOBAL PROPERTY PRO_SRC_FILES)
get_property(${PROJECT_NAME}_HEAD_SOURCE GLOBAL PROPERTY PRO_HEAD_FILES)

# src的头文件
get_property(${PROJECT_NAME}_HEAD_PATH GLOBAL PROPERTY PRO_HEAD_PATH)

# dev_libs的源文件
get_property(${PROJECT_NAME}_THIRD_LIBS GLOBAL PROPERTY LIB_THIRD_LIBS)
# dev_libs的头文件
get_property(${PROJECT_NAME}_THIRD_HEAD_PATH GLOBAL PROPERTY LIB_THIRD_HEAD_PATH)

# get_property(HEAD_HE_FF GLOBAL PROPERTY QT_THIRD_HEAD_PATH)
# message(STATUS "${HEAD_HE_FF}")

# 添加main需要的所有的头文件
include_directories(
    "${CMAKE_CURRENT_LIST_DIR}"
    "${${PROJECT_NAME}_HEAD_PATH}"
    "${${PROJECT_NAME}_THIRD_HEAD_PATH}"
)

# 添加main的源文件

if(CMAKE_SYSTEM_NAME MATCHES "Windows")
    # message(STATUS ${${PROJECT_NAME}_HEAD_SOURCE})
    # 生成可执行目标文件
    # WIN32关闭CMD窗口
    add_executable(${PROJECT_NAME}
        ${${PROJECT_NAME}_HEAD_SOURCE} 
        ${${PROJECT_NAME}_SOURCE}
        # WIN32 logo.rc
        logo.rc
    )

elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
    # message(STATUS ${${PROJECT_NAME}_HEAD_SOURCE})
    # 生成可执行目标文件
    add_executable(
        ${PROJECT_NAME}
        ${${PROJECT_NAME}_HEAD_SOURCE} 
        ${${PROJECT_NAME}_SOURCE}
    )
endif()

# 链接可执行文件的头文件
# target_link_directories(Tutorial PRIVATE "${opencv_dir}"/lib)
target_include_directories(${PROJECT_NAME} PRIVATE ${${PROJECT_NAME}_THIRD_HEAD_PATH})

# 使用全路径链接或系统默认路径链接可执行文件的库
# 注意dll、lib必须是存在的,底层查找lib时,不会自动补充lib前缀
# target_link_libraries(${PROJECT_NAME} PRIVATE dl pthread rt)
# target_link_libraries(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/libs/lib/libzlog.a)

# target_link_libraries的item参数是lib name,
# 让CMake可以通过lib name找到对应的lib文件,
# 需要设置库包含目录,如果item参数是lib path、target name,
# 则不需要设置库包含目录

# 链接可执行文件的第三方库
# target_link_libraries(Tutorial PRIVATE OpenCV)
target_link_libraries(${PROJECT_NAME} PRIVATE ${${PROJECT_NAME}_THIRD_LIBS})

# 不需要Pack打包时使用绝对路径
if(NOT WPACK)
    # 安装可执行文件和头文件
    install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_SOURCE_DIR}/install/bin)

    install(FILES ${${PROJECT_NAME}_HEAD_SOURCE} DESTINATION ${CMAKE_SOURCE_DIR}/install/inc)

    # 安装内置库文件和工具
    # cmake version 3.10.2 方式
    set(INSTALL_TARGETS ${PROJECT_NAME})
    install(TARGETS ${PROJECT_NAME}
        LIBRARY DESTINATION ${CMAKE_SOURCE_DIR}/install/sys/lib # .so/.dylib file
        ARCHIVE DESTINATION ${CMAKE_SOURCE_DIR}/install/sys/lib # .lib file
        RUNTIME DESTINATION ${CMAKE_SOURCE_DIR}/install/sys/bin # .dll file
    )

    # 安装内置库文件和工具
    # cmake version 3.20.6 方式
    # set(INSTALL_TARGETS ${${PROJECT_NAME}_THIRD_LIBS} ${PROJECT_NAME})
    # install(TARGETS ${INSTALL_TARGETS}
    #     LIBRARY DESTINATION ${CMAKE_SOURCE_DIR}/install/sys/lib # .so/.dylib file
    #     ARCHIVE DESTINATION ${CMAKE_SOURCE_DIR}/install/sys/lib # .lib file
    #     RUNTIME DESTINATION ${CMAKE_SOURCE_DIR}/install/sys/bin              # .dll file
    # )

    # 增加自动make install命令
    # add_custom_target(install_target
    #     COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target install
    #     COMMENT "Running make install"
    # )

    # add_dependencies(${PROJECT_NAME} install_target)
else()
    # Pack时使用相对路径
    set(INSTALL_TARGETS ${PROJECT_NAME})
    install(TARGETS ${PROJECT_NAME}
        LIBRARY DESTINATION ${EXEC_INSTALL_LIB} # .so/.dylib file
        ARCHIVE DESTINATION ${EXEC_INSTALL_LIB} # .lib file
        RUNTIME DESTINATION ${EXEC_INSTALL_BIN} # .dll file
    )
endif()


